package org.spring.springboot.config.limit;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

//线程池配置
@Configuration
public class TreadPoolConfig {
  /**
   * 消费队列线程
   * @return
   */
  @Bean(value = "consumerQueueThreadPool")
  public ExecutorService buildConsumerQueueThreadPool(){
      ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
              .setNameFormat("consumer-queue-thread-%d").build();

      ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS,
              new ArrayBlockingQueue<Runnable>(5),namedThreadFactory,new ThreadPoolExecutor.AbortPolicy());

      return pool ;
  }
}
